<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
	<style>
        html,body,.container{
            height: 100%;
        }
		.container {
			display:flex;
		}
		textarea {
			flex-grow: 1;
		}
	</style>	
</head>
<body>
	<div class="container">
		<textarea name="" id="text" cols="30"></textarea>
		<button id="submit" onclick="submit()">转换</button>
		<textarea name="" id="text2" cols="30"></textarea>
	</div>
    <script>
        function submit(){
            var con = document.getElementById('text').value
            
            con = con.replace(/class=".*?"/ig, value =>{
                value = value.replace('class="','').replace('"','')
                value = value.split(' ')
                console.log(value)
                if(value.length>1){
                    value = value.map(item=>`styles.${item}`)
                    value = `[${value.join(',')}].join(' ')`
                }else{
                    value = `styles.${value}`
                }
                return `className={${value}}`
            });
            document.getElementById('text2').value = con
           console.log(con)
        }
    </script>
</body>

</html>